package clothes.tools.dao.impl;

import clothes.tools.dao.SellDao;
import clothes.tools.pojo.Sell;

import java.util.List;

public class SellDaoImpl extends BaseDao implements SellDao {
    @Override
    public int addSell(Sell sell) {
        String sql="insert into sell(pid,onum,cid,adress,phone,name) values(?,?,?,?,?,?)";
        return upDate(sql,sell.getPid(),sell.getOnum(),sell.getCid(),sell.getAdress(),sell.getPhone(),sell.getName());
    }

    @Override
    public int deleteSellById(Integer id) {
        String sql="delete from sell where sid=?";
        return upDate(sql,id);
    }

    @Override
    public int updateSell(Sell sell) {
        String sql="update sell set pid=?,onum=?,adress=?,phone=?,name=? where sid=?";
        return upDate(sql,sell.getPid(),sell.getOnum(),sell.getAdress(),sell.getPhone(),sell.getName(),sell.getSid());
    }

    @Override
    public Sell querySellById(Integer id) {
        String sql="select * from sell where sid=?";
        return queryForOne(sql,Sell.class,id);
    }

    @Override
    public List<Sell> querySell() {
        String sql="select * from sell";
        return queryForList(sql,Sell.class);
    }

    @Override
    public List<Sell> querySell(String page, String limit) {
        String sql="select * from sell limit ?,?";
        int page1=Integer.parseInt(page);
        int limit1=Integer.parseInt(limit);
        return queryForList(sql, Sell.class,(page1-1)*limit1,limit1);
    }

    @Override
    public List<Sell> querySelectSell(String page,String limit,String name) {
        String sql="select * from sell where pid like '%"+name+"%' or pname like '%"+name+"%' or sid like '%"+name+"%' limit ?,?";
        int page1=Integer.parseInt(page);
        int limit1=Integer.parseInt(limit);
        return queryForList(sql, Sell.class,(page1-1)*limit1,limit1);
    }
}
